<?php

namespace Biz\model\NewProduct;

//use Doraemon\pockets\datebase\BaseDbModel;
//use Medoo\Medoo;

use Hhz\Medoo\Medoo;
use Hhz\Mysql\BaseDbModel;

class NewProductWinnerListModel extends BaseDbModel
{
    public const _CONFIG_FILE_ = 'db_store';

    public const _CONFIG_SELECT_ = 'db_brand_activity';

    public const _DATABASE_ = 'brand_activity';

    public const _TABLE_NAME = 'new_product_winner_list';

    //状态（0:未填写收货地址,1:奖品未发放,2:奖品已发放,5:奖品已签收,9:删除）
    public const NO_ADDRESS = 0;
    public const NOT_SEND_PRIZE = 1;
    public const SEND_PRIZE = 2;
    public const DELIVERED = 5;
    public const DELETE = 9;
    public const SHARE = 1;
    public const NO_SHARE = 2;

    public const WINNER_STATUS = [
        self::NO_ADDRESS => "未填写收货地址",
        self::NOT_SEND_PRIZE => "未发货",
        self::SEND_PRIZE => "已发货",
        self::DELIVERED => "已签收",
    ];

    //分享动态：1:已分享 2：未分享
    public const SHARED_STATUS = 1;
    public const UNSHARED_STATUS = 2;

    //是否可以分享：1:分享 2：不分享
    public const IS_SHARE_ALLOW = 1;
    public const IS_SHARE_DENY = 2;
    public const JD_IMG = 'https://img.haohaozhu.cn/Biz-imageShow/o_phone/189/a9a9b20u10u00zH00quu24f?w=1080&h=1079.0009250694&iv=1';


    /**
     * 获取一行
     * @param $where
     * @param string $field
     * @return array|mixed|null
     */
    public static function first($where, $field = '*')
    {
        $rs = self::get($field, $where);
        if (!$rs) {
            return null;
        }
        return $rs;
    }

    /**
     * 批量查询
     * @param $where
     * @param  $field
     * @return array|bool
     */
    public static function all($where, $field)
    {
        return self::select($field, $where);
    }

    /**
     * 获取一列的值
     * @param $where
     * @param array $field
     * @return array|bool
     */
    public static function pluck($where, array $field = ['id'])
    {
        return self::select($field, $where);
    }

    /**
     * 从记录中获取单个值
     * @param $where
     * @param string $columns
     * @return array|bool
     */
    public static function value($where, string $columns = 'id')
    {
        return self::get($columns, $where);
    }

    /**
     * 连表查询
     * @param $table
     * @param $main_col
     * @param $attach_col
     * @param $field
     * @param $where
     * @return array|bool
     */
    public static function left_join($table, $main_col, $attach_col, $field, $where)
    {
        $join = ['[>]' . $table => [$main_col => $attach_col]];
        return self::select($join, $field, $where);
    }


    public static function getCountMaps($map)
    {
        return self::select(['cnt' => Medoo::raw('count(nid)'), 'nid'], $map);
    }

    public static function countNoAddress($nid)
    {
        $where['winner_status'] = self::NO_ADDRESS;
        $where['nid'] = $nid;

        return self::count($where);
    }


}